package com.sn.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sn.core.component.page.Pagination;
import com.sn.dao.GiftMapper;
import com.sn.model.Gift;
import com.sn.service.GiftService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/3/21.
 */
@Service
public class GiftServiceImpl implements GiftService {
    @Resource
    private GiftMapper giftMapper;

    public void addGift(Gift gift) {
        gift.setCreatetime(System.currentTimeMillis());
        giftMapper.addGift(gift);

    }

    public void updateGift(Gift gift) {
        giftMapper.updateGift(gift);

    }

    public void deleteGift(Long id) {
        giftMapper.deleteGift(id);

    }

    public Gift detail(Long id) {
        return giftMapper.giftDetail(id);
    }

    public void reduceGift(Long id,int num) {
        //giftMapper.reduceGift(id,num);

    }

    public Pagination queryGifts(Gift gift) {
        Pagination pagination = new Pagination(gift.getPageno(), gift.getPagesize());
        Page<?> ph=PageHelper.offsetPage(pagination.getStart(), pagination.getPageSize());
        List<Gift> gifts = giftMapper.queryGifts( gift);
        pagination.setTotalCount(ph.getTotal());
        pagination.setV(gifts);
        return pagination;
    }
}
